﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.Web.Script.Serialization;
using ServiceStack.Common.Extensions;
using ServiceStack.Redis;

namespace Uranus.Common
{
    public class WebCacheCommon
    {
        public static string AddCache(object value)
        {
            string g = Guid.NewGuid().ToString().Replace("-","");
            HttpRuntime.Cache.Insert(g, value, null, DateTime.Now.AddMinutes(20), TimeSpan.Zero);
            return g;
        }
        public static void AddCache(string key, object value)
        {
            HttpRuntime.Cache.Insert(key, value, null, DateTime.Now.AddMinutes(20), TimeSpan.Zero);
        }
        public static object GetCache(string g)
        {
            return HttpRuntime.Cache[g];
        }

        public static void SetCache(string g, object value)
        {
            HttpRuntime.Cache.Insert(g, value, null, DateTime.Now.AddMinutes(20), TimeSpan.Zero);
        }
        /// <summary>
        /// 设置cache
        /// </summary>
        /// <param name="g"></param>
        /// <param name="value"></param>
        /// <param name="Minutes">过期时间 分钟</param>
        public static void SetCache(string g, object value,int Minutes)
        {
            HttpRuntime.Cache.Insert(g, value, null, DateTime.Now.AddMinutes(Minutes), TimeSpan.Zero);
        }
        public static void DelCache(string g)
        {
            HttpRuntime.Cache.Remove(g);
        }

        public static void AddSession(string key, object value, HttpContextBase httpContextBase)
        {
            httpContextBase.Session[key] = value;
        }
        public static void DelSession(string key, HttpContextBase httpContextBase)
        {
            httpContextBase.Session.Remove(key);
        }
        public static object GetSession(string key, HttpContextBase httpContextBase)
        {
            return httpContextBase.Session[key];
        }
        public static void AddSession(string key, object value, HttpContext httpContext)
        {
            httpContext.Session[key] = value;
        }
        public static void DelSession(string key, HttpContext httpContext)
        {
            httpContext.Session.Remove(key);
        }
        public static object GetSession(string key, HttpContext httpContext)
        {
            return httpContext.Session[key];
        }
    }
}
